package com.meeting.meetingroom_api.entity;

import com.meeting.meetingroom_api.enums.RoomStatus;
import com.meeting.meetingroom_api.enums.MeetingRoomType;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.LocalTime;
// import java.util.List; // For bookings relationship

@Entity
@Table(name = "meeting_rooms")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class MeetingRoom {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "room_id")
    private Integer roomId;

    @Column(name = "name", nullable = false)
    private String name;

    @Enumerated(EnumType.STRING)
    @Column(name = "type", nullable = false)
    private MeetingRoomType type;

    @Column(name = "capacity", nullable = false)
    private Integer capacity;

    @Column(name = "area", nullable = false)
    private Double area; // 面积（平方米）

    //    @Column(name = "has_multimedia", nullable = false)
//    private Boolean hasMultimedia = false;
    // 替换原有 has_multimedia，新增5个独立设备字段
    @Column(name = "has_projector", nullable = false)
    private Boolean hasProjector = false;

    @Column(name = "has_speaker", nullable = false)
    private Boolean hasSpeaker = false;

    @Column(name = "has_network", nullable = false)
    private Boolean hasNetwork = false;

    @Column(name = "has_microphone", nullable = false)
    private Boolean hasMicrophone = false;

    @Column(name = "has_whiteboard", nullable = false)
    private Boolean hasWhiteboard = false;


    @Column(name = "price_per_hour", nullable = false, precision = 10, scale = 2)
    private BigDecimal pricePerHour;

    @Column(name = "operating_start_time", nullable = false)
    private LocalTime operatingStartTime = LocalTime.of(8, 0);

    @Column(name = "operating_end_time", nullable = false)
    private LocalTime operatingEndTime = LocalTime.of(21, 0);

    @Enumerated(EnumType.STRING)
    @Column(name = "status", nullable = false)
    private RoomStatus status = RoomStatus.available;

    @Transient
    private RoomStatus calculatedStatus; // 计算过程的会议室假想状态，仅在内存中使用

    @Lob // For potentially long text
    @Column(name = "description", columnDefinition = "TEXT")
    private String description;

    @CreationTimestamp
    @Column(name = "created_at", updatable = false)
    private LocalDateTime createdAt;

    @UpdateTimestamp
    @Column(name = "updated_at")
    private LocalDateTime updatedAt;

    // 软删除相关字段
    @Column(name = "deleted", nullable = false, columnDefinition = "TINYINT(1) DEFAULT 0")
    private Boolean deleted = false;

    @Column(name = "deleted_at")
    private LocalDateTime deletedAt;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "deleted_by")
    private User deletedBy;

    // Relationships
    // @OneToMany(mappedBy = "room", cascade = CascadeType.ALL, orphanRemoval = true)
    // private List<Booking> bookings;
}